var apiUrl = 'https://landing.card.zhongtuodianshang.cn/api'


var baseUrl = '';
if (process.env.NODE_ENV === 'development') {
	baseUrl = 'https://landing.card.zhongtuodianshang.cn/api'
} else {
	baseUrl = apiUrl
}

const request = (url = '', date = {}, type = 'post', header = {}) => {
	var token = uni.getStorageSync('token') || '';
	return new Promise((resolve, reject) => {
		uni.request({
			method: type,
			url: baseUrl + url,
			data: date,
			header: {
				"Authorization": token
			},
		}).then((res) => {
			resolve(res.data);

			// if (res.data.code == 0) {
			// 	uni.removeStorageSync('token');
			// 	location.href = '/pages/login/login.vue'
			// }
		}).catch(error => {
			console.log('出错了', error)
			reject(error);
		})
	})
}

export default request